﻿# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
project ("ThreadPool")

# 系统环境
if (WIN32)
    # Enable Hot Reload for MSVC compilers if supported.
    if (POLICY CMP0141)
        cmake_policy(SET CMP0141 NEW)
        set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
    endif()
else ()
    # Linux
    set(CMAKE_CXX_COMPILER /usr/bin/g++) 
endif()

# 设置C++标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 包含子项目 普通版本线程池 & 优化版本 THREAD_POOL_PRO
option (THREAD_POOL_PRO "Thread Pool pro version" ON)
if (THREAD_POOL_PRO)
    add_subdirectory("${CMAKE_SOURCE_DIR}/ThreadPool_pro")
else ()
    add_subdirectory("${CMAKE_SOURCE_DIR}/ThreadPool")
endif ()

# 开发模式
option(ENABLE_DEBUG "Enable debug mode" ON)
if(ENABLE_DEBUG)
    add_definitions(-DDEBUG)
    # 添加调试选项
    set(CMAKE_BUILD_TYPE Debug)  # 设置构建类型为Debug
    add_compile_options(-g)      # 添加-g选项以生成调试信息
    add_compile_options(-O0)     # 添加-O0选项以禁用优化

    add_subdirectory("${CMAKE_SOURCE_DIR}/test")
else()
    set(CMAKE_BUILD_TYPE Release)
    add_compile_options(-O2)     # 编译优化
endif()